<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/common.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<input type="hidden" id="orgId" name="orgId">
			<div class='form-group'>
				<label class='col-md-2 control-label'>公司编码</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='公司编码' type='text' name='orgCode' id='orgCode' data-bv-notempty='true' data-bv-notempty-message='公司编码 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>公司类型</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='公司类型ID' type='text' name='orgTypeName' id='orgTypeName' readonly="readonly">
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>公司名称</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='公司名称' type='text' name='orgName' id='orgName' data-bv-notempty='true' data-bv-notempty-message='公司名称 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>公司描述</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='公司描述' type='text' name='orgDes' id='orgDes'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>公司状态</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='公司状态' type='text' name='orgStatus' id='orgStatus' data-bv-notempty='true' data-bv-notempty-message='公司状态 不能为空'>
				</div>
			</div>
			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='orgList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});
		
		initData();
		
		function initData(){
			var id = GetQueryString("id");
			if(id){
				$.ajax({
					type : 'get',
					url : urlRootPrefix + '/orgs/'+id,
					async : false,
					success : function(data) {
						var data = data.data;
						$('#orgId').val(data.orgId);
						$('#orgCode').val(data.orgCode);
						$('#orgTypeName').val(data.orgTypeName);
						$('#orgName').val(data.orgName);
						$('#orgDes').val(data.orgDes);
						$('#orgStatus').val(data.orgStatus);

					}
				});
			}
		}

		function update() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'put',
				url : urlRootPrefix + '/orgs',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					if(!data.success){
						layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
						$("button[type='submit']").removeAttr("disabled");
						return;
					}
					layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                        location.href = "orgList.html";
                    });
				}
			});
		}
		
	</script>
</body>
</html>
